package com.jh.readme.iu.fragment.newslist;

import com.apkfuns.logutils.LogUtils;
import com.jh.tools.bean.NeteastNewsSummary;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import rx.Observer;

/**
 * Created by niejiahuan on 2016/5/31.
 * 主界面控制层
 */
public class NewsListPresenter extends NewsListContract.Presenter {
    private long cPage;
    public List<NeteastNewsSummary> mNeteastVideoSummarys;
    public String newsId;
    @Override
    public void onStart() {
        mNeteastVideoSummarys=new ArrayList<>();
    }

    @Override
    void getInitView(Map<String ,String> params) {
        this.newsId=newsId;
        getNews(params,cPage);//获取初始化页面的数据
    }

    @Override
    void getNews(final Map<String ,String> params,long page) {
        mModel.getNewsDate(params,page).subscribe(new Observer<Map<String, List<NeteastNewsSummary>>>() {
            @Override
            public void onCompleted() {
                //刷新UI
                mView.initNewList(mNeteastVideoSummarys);
                LogUtils.d(mNeteastVideoSummarys.size());
            }

            @Override
            public void onError(Throwable e) {
                if (cPage>=1) {
                    cPage = -1;
                }
            }

            @Override
            public void onNext(Map<String, List<NeteastNewsSummary>> stringListMap) {
                mNeteastVideoSummarys.addAll(stringListMap.get(params.get("news_id")));
            }
        });
    }
}
